<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateConfigsTable extends Migration
{
    /**
     * 数据表名称
     * @var string
     */
    private $tableName = 'configs';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 创建数据表
        Schema::create($this->tableName, function (Blueprint $table) {
            // 数据表类型
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';

            // 数据表字段
            $table->increments('config_id')->comment('递增主键');
            $table->tinyInteger('type', false, true)->comment('配置类型 0:应用配置 1:系统配置');
            $table->string('name', 50)->comment('显示名称');
            $table->string('key', 30)->comment('配置键');
            $table->string('value')->nullable()->comment('配置值');
            $table->text('params')->nullable()->comment('补充参数');
            $table->string('description', 300)->nullable()->comment('配置描述');
            $table->integer('sort',false,true)->default(50)->comment('排序（升序）');
            $table->timestamp('created_at')->comment('数据创建时间')->default(DB::raw('CURRENT_TIMESTAMP'));

            // 数据表索引
            $table->index('config_id');
            $table->unique('key');
        });
        // 设置数据表备注信息
        DB::statement("ALTER TABLE `".env('DB_PREFIX')."{$this->tableName}` COMMENT'系统配置表'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
}
